package com.briup.jz.web.controller;

import java.util.List;
import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.briup.jz.bean.BaseRolePrivilege;
import com.briup.jz.service.IBaseRolePrivilegeService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api(description="角色权限对应关系接口")
@Validated
@RestController
@RequestMapping("/roleprivilege")
public class BaseRolePrivilegeController {
	@Autowired
    private IBaseRolePrivilegeService baseRolePrivilegeService;

    @ApiOperation(value = "查询所有角色权限关系")
    @GetMapping("query")
    public Message query(Long id){
        List<BaseRolePrivilege> list = baseRolePrivilegeService.query(id);
        return MessageUtil.success(list);
    }

    @ApiOperation(value = "通过id删除")
    @DeleteMapping("deleteById")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
    public Message deleteById(@NotNull Long id){
    	baseRolePrivilegeService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "保存或更新角色关系对应关系信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "主键",paramType = "form"),
            @ApiImplicitParam(name="roleId",value = "角色id",paramType = "form",required = true),
            @ApiImplicitParam(name="privilegeId",value = "权限id",paramType = "form",required = true),
    })
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(BaseRolePrivilege BaseRolePrivilege){
    	baseRolePrivilegeService.saveOrUpdate(BaseRolePrivilege);
        return MessageUtil.success("更新成功");
    }
}
